<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>矩阵快速幂的C&#43;&#43;封装 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="矩阵快速幂的C&#43;&#43;封装"><meta property="og:title" content="矩阵快速幂的C&#43;&#43;封装" />
<meta property="og:description" content="矩阵快速幂的C&#43;&#43;封装" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-01-20T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-01-20T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="矩阵快速幂的C&#43;&#43;封装"/>
<meta name="twitter:description" content="矩阵快速幂的C&#43;&#43;封装"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" /><link rel="prev" href="https://acking-you.github.io/posts/%E6%89%8B%E5%86%99http%E5%8D%8F%E8%AE%AE%E8%A7%A3%E6%9E%90%E5%99%A8/" /><link rel="next" href="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "矩阵快速幂的C++封装",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c\u002b\u002b%E5%B0%81%E8%A3%85\/"
        },"genre": "posts","keywords": "矩阵快速幂","wordcount":  7776 ,
        "url": "https:\/\/acking-you.github.io\/posts\/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c\u002b\u002b%E5%B0%81%E8%A3%85\/","datePublished": "2022-01-20T00:00:00+00:00","dateModified": "2022-01-20T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "矩阵快速幂的C++封装"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center, https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center"
        title="矩阵快速幂的C&#43;&#43;封装" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">矩阵快速幂的C&#43;&#43;封装</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/c++%E5%AE%9E%E6%88%98/"><i class="far fa-folder fa-fw"></i>C++实战</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-01-20">2022-01-20</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 7776 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 16 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#什么是矩阵快速幂">什么是矩阵快速幂？</a>
      <ul>
        <li><a href="#怎么进行矩阵快速幂的运算">怎么进行矩阵快速幂的运算？</a></li>
      </ul>
    </li>
    <li><a href="#为什么突然想写这个模板">为什么突然想写这个模板？</a>
      <ul>
        <li><a href="#题目">题目</a></li>
        <li><a href="#我是如何被坑的">我是如何被坑的</a></li>
      </ul>
    </li>
    <li><a href="#教你设计matrix类">教你设计Matrix类</a>
      <ul>
        <li><a href="#如何设计一个类">如何设计一个类？</a></li>
        <li><a href="#类的具体抽象结构代码的具体规划图">类的具体抽象结构（代码的具体规划图）</a></li>
        <li><a href="#实现矩阵泛型模板类">实现矩阵泛型模板类</a></li>
      </ul>
    </li>
    <li><a href="#总结">总结</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h1 id="实现源码在线查看">实现源码在线查看</h1>
<p>如果对于类的设计已经非常清楚，只是进来想看看我的这个泛型模板源代码，那么直接点到下面这个链接进行查看：
<a href="https://github1s.com/ACking-you/my_tiny_stl/blob/HEAD/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%A8%A1%E6%9D%BF%E7%9A%84%E5%B0%81%E8%A3%85/Matrix.hpp" target="_blank" rel="noopener noreffer">源码链接</a></p>
<h2 id="什么是矩阵快速幂">什么是矩阵快速幂？</h2>
<ul>
<li>关于快速幂，就是利用二进制进行求解某个数的幂的快速方法。</li>
</ul>
<p>后面会对快速幂的原理进行简单讲解，如果还是不懂，请自行百度。</p>
<p>相信有很多小伙伴是初入大学的世界，可能还没学过线性代数（比如我），于是乎不知道矩阵是什么，我推荐一个网站去看看矩阵的乘法是怎么运算的，下面是网站链接：（话说how to这个网站还真是牛批，什么东西都有教程，而且质量还贼高！😂）</p>
<p><a href="https://zh.wikihow.com/%E8%AE%A1%E7%AE%97%E7%9F%A9%E9%98%B5%E4%B9%98%E6%B3%95#:~:text=%E8%A6%81%E8%AE%A1%E7%AE%97%E7%9F%A9%E9%98%B5%E7%9A%84%E4%B9%98%E6%B3%95,%E5%86%8D%E8%AE%A1%E7%AE%97%E5%AE%83%E4%BB%AC%E7%9A%84%E5%92%8C%E3%80%82" target="_blank" rel="noopener noreffer">矩阵乘法的计算方式</a></p>
<p>那么如何用代码表示矩阵以及他的乘法呢？</p>
<p>其实很简单，就是三层循环进行控制即可。
如：我这里是C++的重载运算符 Matrix 是我定义的一个类。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="n">Matrix</span><span class="o">&amp;</span> <span class="k">operator</span><span class="o">*</span><span class="p">(</span><span class="n">Matrix</span><span class="o">&amp;</span> <span class="n">b</span><span class="p">){</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">m</span><span class="o">==</span><span class="n">b</span><span class="p">.</span><span class="n">n</span><span class="p">);</span>
        <span class="n">ll</span> <span class="n">tmp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">];</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
                <span class="n">ll</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="n">m</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">){</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">+</span> <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">this</span><span class="o">-&gt;</span><span class="n">m</span> <span class="o">=</span> <span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">;</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>
</code></pre></div><h3 id="怎么进行矩阵快速幂的运算">怎么进行矩阵快速幂的运算？</h3>
<p>关于如何矩阵快速幂，我们先了解一下简单的快速幂。</p>
<p>说是快速幂就是通过位运算实现快速的同数累乘。
简述一下快速幂的原理：</p>
<p>原理就是，如果要求x的3次幂，那么可以转化为求 <code>x*x</code> 的 <code>2</code> 次幂，而求一个数的 <code>2^n</code> 幂是很简单的，比如进行一次 <code>x *= x</code> 便得到 <code>x</code> 的二次方。而再进行一次 <code>x *= x</code> 就得到了 <code>4</code> 次方，继续便可得到 <code>8/16...</code> 总之是 <code>log2N</code> 的时间。</p>
<p>代码如下：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">int</span> <span class="nf">QuickPow</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">){</span>
    <span class="kt">int</span> <span class="n">c</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">res</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">while</span><span class="p">(</span><span class="n">c</span><span class="o">!=</span><span class="mi">0</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">&amp;</span><span class="mi">1</span><span class="o">!=</span><span class="mi">0</span><span class="p">){</span>
            <span class="n">res</span> <span class="o">*=</span> <span class="n">x</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">c</span> <span class="o">&gt;&gt;=</span> <span class="mi">1</span><span class="p">;</span>
        <span class="n">x</span> <span class="o">*=</span> <span class="n">x</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><ul>
<li>那么矩阵的快速幂如何进行？
把上述的 int 类型换成自己定义的矩阵就是矩阵的快速幂了。</li>
</ul>
<p>我直接贴上C++实现的重载运算符后的类的快速幂写法：</p>
<blockquote>
<p>这里的quickPow表示的是一个类的成员函数，所以可以直接用到这个矩阵里的数据进行运算。this表示指向这个对象的指针。init() 成员函数表示初始化为单位矩阵。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">    <span class="kt">void</span> <span class="nf">quickPow</span><span class="p">(</span><span class="n">ll</span> <span class="n">c</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="mi">1</span><span class="o">||</span><span class="n">c</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">)</span><span class="k">return</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="mi">0</span><span class="p">){</span>
            <span class="n">init</span><span class="p">();</span>
            <span class="k">return</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">Matrix</span> <span class="n">tmp</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="n">init</span><span class="p">();</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">c</span><span class="p">){</span>
            <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">&amp;</span><span class="mi">1</span><span class="p">){</span>
                <span class="o">*</span><span class="k">this</span> <span class="o">=</span> <span class="o">*</span><span class="k">this</span> <span class="o">*</span> <span class="n">tmp</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">c</span> <span class="o">&gt;&gt;=</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">*</span><span class="n">tmp</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
</code></pre></div><h2 id="为什么突然想写这个模板">为什么突然想写这个模板？</h2>
<p>主要是因为最近做了几道快速幂的题目，被坑的很惨，然后就突然想设计一个模板了，主要是 <a href="https://github.com/ACking-you/my_tiny_stl/tree/4b5d24d7414ecd3559484cd664b41d63f102182e" target="_blank" rel="noopener noreffer">my_tiny_stl</a> 这个仓库也好久没更新了😂</p>
<h3 id="题目">题目</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/1216a424e8b6428e8e1784c383fa7a99.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" />
<a href="http://lx.lanqiao.cn/problem.page?gpid=D367" target="_blank" rel="noopener noreffer">OJ网站</a></p>
<h3 id="我是如何被坑的">我是如何被坑的</h3>
<ul>
<li>首先拿到这道题，我便马上开始简单的O(n)递推法实现，然后提交，然后。。超时。。</li>
</ul>
<p>定眼一看，数据量原来这么大！</p>
<p>后面一想，肯定是矩阵快速幂了，先想出以下矩阵的递推式子：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/20200211184203335.png#pic_left"
        data-srcset="https://img-blog.csdnimg.cn/20200211184203335.png#pic_left, https://img-blog.csdnimg.cn/20200211184203335.png#pic_left 1.5x, https://img-blog.csdnimg.cn/20200211184203335.png#pic_left 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/20200211184203335.png#pic_left"
        title="https://img-blog.csdnimg.cn/20200211184203335.png#pic_left" />
进而题目便可得到求解。</p>
<p>然后我就利用 C++ 的类简单的封装了一个矩阵类，里面重载了乘法和 <code>quickpow</code> 方法，然后比较悠闲的准备提交，还没提交前就遇到C++的语法陷阱、、</p>
<h4 id="语法陷阱建议非c党绕道">语法陷阱（建议非C++党绕道）</h4>
<p>由于类用的都是堆内存，所以我写了析构函数，我遇到的问题出在重载乘法时我返回的是左值，而且我也没有对 &lsquo;=&rsquo; 进行重载，所以 ‘=’ 就是直接的成员变量拷贝，这导致一个结果就是两个对象的 date 指向同一片内存空间，而之前的那片内存空间泄露了，且最后这两个对象肯定都会调用析构函数，这又导致了析构函数调用了两次！</p>
<ul>
<li>如何解决这个问题？如果是 <code>C++98</code> ，那么这个问题很大，基本上就是两种方法解决：</li>
</ul>
<ol>
<li>逃避问题，乘法的左操作数必须是当前赋值对象，这样就避免了最后赋值语句将原本对象内的指针直接改变。</li>
<li>解决问题，解决这类问题无论是 <code>C++11</code> 还是 <code>C++98</code> 最直接的方式就是重载 <code>‘=’ </code> 号，重载 <code>'=' </code> 号的实现根据具体的情况进行，而具体实现赋值的重载，我们需要考虑两件事：第一，<strong>需尽可能的减少内存的申请和使用</strong>（具体而言就是判断两个对象的指针所指向的是否为同一片空间，即便不是同一片空间，为了增加空间利用率还可以判断两个空间是否大小一致，然后进行拷贝即可）。第二，<strong>如果是临时对象则需要把它的指针置空</strong>（防止编译器未优化临时变量的析构函数，从而调用了析构函数多次析构同一内存）。</li>
</ol>
<ul>
<li>由于 <code>C++11</code> 开始<strong>有了右值引用和它配套的移动赋值构造器</strong>，所以可以把临时变量直接调用移动构造器变成具名对象，然后进行操作，一般就是把它的指针所有权进行转移，然后把它的指针置空防止析构错误，在我的理解下，<strong>右值引用的出现就是为了捕捉到匿名对象然后给程序员进行适当的性能优化操作</strong>，没有右值引用前，匿名对象的内存根本就没法去使用，只能用来简单的赋值拷贝操作后才能使用，这样就很消耗内存了，右值引用出现后，我们可以通过右值引用对匿名对象进行捕捉，然后操作它的底层内存。还有一个很大的内存相关的更新就是<strong>有了一个 <code>nullptr</code> 关键字，这个关键字使得空指针不再会有歧义，所以 <code>delete nullptr</code> 是安全的</strong>。所以防止多次 <code>delete</code> 同一片空间产生错误可以将它赋值为 <code>nullptr</code> 即可。</li>
<li>那么基于 <code>C++11</code> 这个问题该如何解决呢？<strong>解决方法和C++98没差，就是能够更加得心应手的进行内存的管理了</strong>，如果等号右边是一个右值，那么它肯定是一个临时对象，所以我们可以在 &lsquo;=&rsquo; 号的重载中直接了当的用它的内存，并把它的指针置空。如果没有右值类型进行捕获，编译器默认也是会对临时对象进行优化的，也能防止产生多个对象的赋值拷贝，<strong>但只能在对象初始化的时候进行优化</strong>！而在<strong>其他时候则还是会调用析构函数</strong>，这个时候如果还是用编译器默认产生的 &lsquo;=&rsquo; 重载，则会发生被析构的空间的指针被赋值的情况，而我们的右值引用版本的赋值重载便是针对此现象的。这样便于内存管理，将右值和左值进行分开处理。<strong>右值是临时变量只需要用一会儿，所以可以直接把它的内存拿过来继续用，也不会对程序逻辑造成影响，而左值则不一样，它还需要存活很长一段时间，所以我们需要另创空间进行拷贝。</strong></li>
</ul>
<blockquote>
<p>特别提醒：<strong>如果是做算法题，则完全不用去考虑内存的管理，析构函数也不要去写，毕竟只需要单次调用使用</strong>，对象最多也就存在一会儿。</p>
</blockquote>
<h4 id="做题陷阱">做题陷阱</h4>
<blockquote>
<p>在必要的时候千万不要舍不得开long long！！！！</p>
</blockquote>
<p>这道题的数据量无论是幂的次方还是整个记录过程的数据都要开long long！！！
我被这个陷阱坑了无数回了，这一次也不另外😅</p>
<p>开始写完这种之后过了前5个，然后后面5个报错，我还以为我设计的这个类有问题，还特意去写了好几个普通C语言版本😂最后发现原来的没开long long。以下为更改long long后的代码通过版本，我用宏定义写了几个版本。。。</p>
<blockquote>
<p>这个Matrix类的设计还是很多地方没有考虑到位，比如上一个陷阱的问题只是通过方法一得到解决，并未去重载赋值操作符。。。所以后面痛定思痛，设计一个较为可用的Matrix类！</p>
</blockquote>
<ul>
<li>效率时快时慢的，这主要取决于编译器是否进行优化。
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_19,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_19%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_19%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_19%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_19,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/4e07b69ac9f94c6a89bcae443fe5738d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_19,color_FFFFFF,t_70,g_se,x_16" /></li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//
</span><span class="c1">// Created by Alone on 2021/11/19.
</span><span class="c1">//
</span><span class="c1"></span><span class="cp">#include</span> <span class="cpf">&lt;bits/stdc++.h&gt;</span><span class="cp">
</span><span class="cp"></span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="c1">//#define ELSE_MAIN
</span><span class="c1"></span><span class="cp">#define MY_MAIN
</span><span class="cp">#define MAT
</span><span class="cp">#ifdef MAT
</span><span class="cp"></span><span class="k">typedef</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">ll</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">Matrix</span><span class="p">{</span>
    <span class="n">ll</span><span class="o">**</span> <span class="n">date</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">m</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span> <span class="k">static</span> <span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">Matrix</span><span class="p">(</span><span class="n">ll</span><span class="o">**</span> <span class="n">rec</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="kt">int</span> <span class="n">m</span><span class="p">)</span><span class="o">:</span><span class="n">date</span><span class="p">(</span><span class="n">rec</span><span class="p">),</span><span class="n">n</span><span class="p">(</span><span class="n">n</span><span class="p">),</span><span class="n">m</span><span class="p">(</span><span class="n">m</span><span class="p">){}</span><span class="c1">//C风格的初始化
</span><span class="c1"></span>    <span class="n">Matrix</span><span class="p">()</span><span class="o">:</span><span class="n">date</span><span class="p">(</span><span class="nb">NULL</span><span class="p">),</span><span class="n">m</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span><span class="n">n</span><span class="p">(</span><span class="mi">0</span><span class="p">){}</span> <span class="c1">//缺省
</span><span class="c1"></span>    <span class="n">Matrix</span><span class="p">(</span><span class="n">Matrix</span><span class="o">&amp;</span> <span class="n">b</span><span class="p">)</span><span class="o">:</span><span class="n">n</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">n</span><span class="p">),</span><span class="n">m</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">){</span><span class="c1">//拷贝构造
</span><span class="c1"></span>        <span class="n">assert</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">b</span><span class="p">.</span><span class="n">n</span><span class="o">&gt;</span><span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span>
        <span class="n">date</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
        <span class="n">copy</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="p">,</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="o">+</span><span class="n">n</span><span class="p">,</span><span class="n">date</span><span class="p">);</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="p">[</span><span class="n">m</span><span class="p">];</span>
            <span class="n">copy</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">m</span><span class="p">,</span><span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="o">~</span><span class="n">Matrix</span><span class="p">(){</span><span class="c1">//析构函数实现
</span><span class="c1"></span>        <span class="n">assert</span><span class="p">(</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">n</span><span class="o">&gt;</span><span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&gt;=</span><span class="mi">0</span> <span class="p">;</span> <span class="o">--</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">delete</span> <span class="p">[]</span> <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
        <span class="p">}</span>
        <span class="k">delete</span><span class="p">[]</span> <span class="n">date</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">Matrix</span><span class="o">&amp;</span> <span class="k">operator</span><span class="o">*</span><span class="p">(</span><span class="n">Matrix</span><span class="o">&amp;</span> <span class="n">b</span><span class="p">){</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">m</span><span class="o">==</span><span class="n">b</span><span class="p">.</span><span class="n">n</span><span class="p">);</span>
        <span class="n">ll</span> <span class="n">tmp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">];</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
                <span class="n">ll</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="n">m</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">){</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">+</span> <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">.</span><span class="n">date</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">this</span><span class="o">-&gt;</span><span class="n">m</span> <span class="o">=</span> <span class="n">b</span><span class="p">.</span><span class="n">m</span><span class="p">;</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">init</span><span class="p">(){</span><span class="c1">//重新初始化为单位矩阵
</span><span class="c1"></span>        <span class="n">assert</span><span class="p">(</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">n</span><span class="o">&gt;</span><span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">if</span><span class="p">(</span><span class="n">i</span><span class="o">==</span><span class="n">j</span><span class="p">)</span><span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
                <span class="k">else</span> <span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="kt">void</span> <span class="nf">quickPow</span><span class="p">(</span><span class="n">ll</span> <span class="n">c</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="mi">1</span><span class="o">||</span><span class="n">c</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">)</span><span class="k">return</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="mi">0</span><span class="p">){</span>
            <span class="n">init</span><span class="p">();</span>
            <span class="k">return</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">Matrix</span> <span class="n">tmp</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="n">init</span><span class="p">();</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">c</span><span class="p">){</span>
            <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">&amp;</span><span class="mi">1</span><span class="p">){</span>
                <span class="o">*</span><span class="k">this</span> <span class="o">=</span> <span class="o">*</span><span class="k">this</span> <span class="o">*</span> <span class="n">tmp</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">c</span> <span class="o">&gt;&gt;=</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">*</span><span class="n">tmp</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="kt">void</span> <span class="nf">print</span><span class="p">(){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
                <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">date</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">&lt;&lt;</span><span class="sc">&#39; &#39;</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="kt">int</span> <span class="nf">get</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="kt">int</span> <span class="n">y</span><span class="p">){</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">date</span><span class="o">!=</span><span class="nb">NULL</span> <span class="o">&amp;&amp;</span> <span class="n">x</span><span class="o">&lt;</span><span class="n">n</span> <span class="o">&amp;&amp;</span> <span class="n">y</span><span class="o">&lt;</span><span class="n">m</span><span class="p">);</span>
        <span class="k">return</span> <span class="n">date</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">];</span>
    <span class="p">}</span>
<span class="p">};</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">Matrix</span><span class="o">::</span><span class="n">MOD</span> <span class="o">=</span> <span class="mf">1e9</span><span class="o">+</span><span class="mi">7</span><span class="p">;</span>
<span class="cp">#endif
</span><span class="cp"></span>

<span class="cp">#ifdef MY_MAIN
</span><span class="cp"></span><span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="n">ll</span> <span class="n">c</span><span class="p">;</span>
    <span class="n">cin</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">;</span>
    <span class="n">ll</span><span class="o">**</span> <span class="n">matrix</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="o">*</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
    <span class="n">matrix</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="p">[</span><span class="mi">2</span><span class="p">]{</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">};</span>
    <span class="n">matrix</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="p">[</span><span class="mi">2</span><span class="p">]{</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">};</span>
    <span class="n">Matrix</span> <span class="n">mat</span><span class="p">(</span><span class="n">matrix</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
    <span class="n">mat</span><span class="p">.</span><span class="n">quickPow</span><span class="p">(</span><span class="n">c</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
    <span class="c1">//mat.print();
</span><span class="c1"></span>
    <span class="n">ll</span><span class="o">**</span> <span class="n">res</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="o">*</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
    <span class="n">res</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
    <span class="n">res</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ll</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
    <span class="n">res</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="n">Matrix</span> <span class="n">fib</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>

    <span class="c1">//这里有个内存分配错误，mat*fib返回的是左值，而=没有重载默认直接赋值成员变量。
</span><span class="c1"></span>    <span class="c1">//直接导致了fib失去了之前的变量所有权，和mat共同有一个内存空间，这样导致同一片空间被free两次
</span><span class="c1"></span>    <span class="c1">//通过重载 = 号解决，防止直接的内存没有被释放就重新绑定同一片内存
</span><span class="c1"></span>    <span class="n">Matrix</span> <span class="n">ret</span><span class="p">(</span><span class="n">mat</span><span class="o">*</span><span class="n">fib</span><span class="p">);</span>
    <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">ret</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span>

    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="cp">#endif
</span><span class="cp"></span>
<span class="cp">#ifdef TEST_MAIN
</span><span class="cp"></span><span class="k">typedef</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">ll</span> <span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span> <span class="o">=</span> <span class="mf">1e9</span><span class="o">+</span><span class="mi">7</span><span class="p">;</span>
<span class="n">ll</span> <span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]{{</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">},{</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">}};</span><span class="n">ll</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">]{</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">};</span>
<span class="kt">void</span> <span class="nf">selfMut</span><span class="p">(){</span>
    <span class="n">ll</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
            <span class="n">ll</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">){</span>
                <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span><span class="o">+</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="n">memmove</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="k">sizeof</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
    <span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">difMut</span><span class="p">(){</span>
    <span class="n">ll</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="n">ll</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">){</span>
            <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">+</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
    <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">Mut</span><span class="p">(</span><span class="n">ll</span> <span class="n">_a</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span><span class="n">ll</span> <span class="n">_b</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span><span class="kt">int</span> <span class="n">n1</span><span class="p">,</span><span class="kt">int</span> <span class="n">m1</span><span class="p">,</span><span class="kt">int</span> <span class="n">n2</span><span class="p">,</span><span class="kt">int</span> <span class="n">m2</span><span class="p">){</span>
    <span class="k">if</span><span class="p">(</span><span class="n">m1</span><span class="o">!=</span><span class="n">n2</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">;</span>
    <span class="kt">int</span> <span class="n">tmp</span><span class="p">[</span><span class="n">n1</span><span class="p">][</span><span class="n">m2</span><span class="p">];</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n1</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">m2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
            <span class="n">ll</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="n">m1</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">){</span>
                <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span><span class="o">+</span><span class="n">_a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">_b</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n1</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">m2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
            <span class="n">_a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">quickPow</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="p">){</span>
    <span class="n">ll</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]{{</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">},{</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">}};</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">k</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">k</span><span class="o">&amp;</span><span class="mi">1</span><span class="p">){</span>
            <span class="n">Mut</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">k</span><span class="o">&gt;&gt;=</span><span class="mi">1</span><span class="p">;</span>
        <span class="n">selfMut</span><span class="p">();</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="n">memmove</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="k">sizeof</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
    <span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="kt">int</span> <span class="n">c</span><span class="p">;</span>
    <span class="n">cin</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">;</span>
    <span class="n">quickPow</span><span class="p">(</span><span class="n">c</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">){</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%d &#34;</span><span class="p">,</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
        <span class="p">}</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">difMut</span><span class="p">();</span>
    <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
<span class="cp">#endif
</span><span class="cp"></span>

<span class="cp">#ifdef ELSE_MAIN
</span><span class="cp"></span>

<span class="k">const</span> <span class="kt">long</span> <span class="kt">long</span> <span class="kt">int</span> <span class="n">p</span> <span class="o">=</span> <span class="mi">1000000007</span><span class="p">;</span>

<span class="k">struct</span> <span class="nc">Mat</span>
<span class="p">{</span>
	<span class="kt">long</span> <span class="kt">long</span> <span class="kt">int</span> <span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="p">};</span>

<span class="n">Mat</span> <span class="n">ans</span><span class="p">,</span> <span class="n">base</span><span class="p">;</span>

<span class="n">Mat</span> <span class="nf">Mul</span><span class="p">(</span><span class="n">Mat</span> <span class="n">x</span><span class="p">,</span> <span class="n">Mat</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
	<span class="n">Mat</span> <span class="n">c</span><span class="p">;</span>
	<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
		<span class="p">{</span>
			<span class="n">c</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
			<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
			<span class="p">{</span>
				<span class="n">c</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="n">x</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">y</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">%</span> <span class="n">p</span><span class="p">;</span>
			<span class="p">}</span>
		<span class="p">}</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="n">c</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">Qpow</span><span class="p">(</span><span class="kt">long</span> <span class="kt">long</span> <span class="kt">int</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
	<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
		<span class="p">{</span>
			<span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">j</span><span class="p">)</span>
			<span class="p">{</span>
				<span class="n">ans</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
			<span class="p">}</span>
			<span class="k">else</span>
			<span class="p">{</span>
				<span class="n">ans</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
			<span class="p">}</span>
			<span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="n">j</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
			<span class="p">{</span>
				<span class="n">base</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
			<span class="p">}</span>
			<span class="k">else</span>
			<span class="p">{</span>
				<span class="n">base</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
			<span class="p">}</span>
		<span class="p">}</span>
	<span class="p">}</span><span class="c1">//这一段为了初始化ans为单位矩阵，将base初始化为要求的n次幂的矩阵
</span><span class="c1"></span>
	<span class="k">while</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="k">if</span><span class="p">(</span><span class="n">n</span> <span class="o">&amp;</span> <span class="mi">1</span><span class="p">)</span>
		<span class="p">{</span>
			<span class="n">ans</span> <span class="o">=</span> <span class="n">Mul</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">base</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="n">base</span> <span class="o">=</span> <span class="n">Mul</span><span class="p">(</span><span class="n">base</span><span class="p">,</span> <span class="n">base</span><span class="p">);</span>
		<span class="n">n</span> <span class="o">&gt;&gt;=</span> <span class="mi">1</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="n">ans</span><span class="p">.</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
	<span class="kt">long</span> <span class="kt">long</span> <span class="kt">int</span> <span class="n">n</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
	<span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="n">n</span><span class="p">;</span>
	<span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">Qpow</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>


<span class="cp">#endif
</span></code></pre></div><h2 id="教你设计matrix类">教你设计Matrix类</h2>
<h3 id="如何设计一个类">如何设计一个类？</h3>
<p>结构：</p>
<ul>
<li>内部数据抽象：对象的运算数据存储
<ol>
<li>用二级指针 date 进行矩阵的二维空间的内存管理，以及n和m表示矩阵的行高和列宽。</li>
</ol>
</li>
<li>行为抽象：对对象的行为描述
<ol>
<li>构造函数（缺省、自定义、拷贝、移动） 和 析构函数（调用destory成员函数）。</li>
<li>setter 和 getter。提供函数接口去设置和得到数据。</li>
<li>功能函数：比如重载的乘法运算符和快速幂函数这些都算功能函数。</li>
</ol>
</li>
</ul>
<p>对象的属性抽象：</p>
<ol>
<li><strong>数据和行为是否对外</strong>，对外封装数据的意义在于防止对对象行为描述的破坏，而对外开放的某个行为通常需要内部多个函数进行重复调用来实现。这个时候需要用到 <code>public</code> 和 <code>private</code> 关键字进行修饰。</li>
<li><strong>数据和行为是否可继承</strong>，对于某些行为（函数），我们不想被外部调用，但是对子类又很有用，这个时候我们可以采取 <code>protect</code> 关键字进行修饰。</li>
<li><strong>数据和行为是否能重复利用</strong>，为了节省不必要的内存开销，可以设计不需要产生具体对象的通用型函数，可以使用 <code>static</code> 关键字进行修饰，这样可以避免我想使用某个函数前还得去申请一片毫不相关的内存空间，而对于某个对象的数据也可以采用 <code>static</code> 进行修饰，这样一来，这个数据在对象的创建过程中就不需要再进行申请和赋值了。</li>
</ol>
<p>那么接下来就来确定行为（函数）的属性了，数据肯定是不对外开放的（private），否则面向对象将毫无意义。</p>
<ol>
<li>构造函数 和 析构函数，这两个是对象的创建和销毁的关键，所以如果不是希望对象不被创建或者是不被销毁，都应该使用 <code>public</code> 修饰。</li>
<li>setter 和 getter。很明显是对外开放的接口函数，所以肯定也是 <code>public</code> 修饰。</li>
<li>功能函数：矩阵快速幂的函数，很明显我们希望设置一个对外通用的情况，那么这个时候就应该不需要创建对象便可进行调用，所以最好用 <code>static</code> 进行修饰（这个一般为外部通用接口，内部还需实现一个方便类调用的版本，这也很简单，直接传参调用该函数即可），重载的乘法肯定也是对外的所以需要 <code>public</code> 修饰，<code>destroy</code> 函数用于处理内存的回收，很明显这是一个内部通用的函数，但是外界完全是不需要它的！所以把它设置为 <code>private</code> 属性即可。</li>
</ol>
<p>以上便是对整个类的设计思路，当然真正动手设计的时候，还需要具体到函数的参数和返回值类型，因为这牵扯到 C++ 的具体语法了，比如我应该在重载乘法的时候返回一个什么样的类型？最好是返回一个右值！而重载赋值运算符则最好是返回一个左值。<strong>一般需要考虑返回值类型的取舍时，最难的就是如果返回一个对象，我该返回左值还是右值。</strong></p>
<blockquote>
<p>写了这么久C++，我感觉用C++写的Java屏蔽重载运算符的特性主要就是重载运算符时需要考虑的过程太多了，C++菜鸡（我就是这个菜鸟😂）写出及其低效且不安全的代码，而只有老鸟才能写出优雅高效的代码。</p>
</blockquote>
<h3 id="类的具体抽象结构代码的具体规划图">类的具体抽象结构（代码的具体规划图）</h3>
<blockquote>
<p><strong>按照属性对类的各个部分进行分类的，毕竟属性也基本就代表了这个方法的使用场景了。</strong></p>
</blockquote>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/e3811dd91b944245b6028a1b494de1e1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<ul>
<li>最后可以利用基本的断言或者异常，让代码变得更为健壮，使得更容易定位错误发生的位置和原因。</li>
</ul>
<h3 id="实现矩阵泛型模板类">实现矩阵泛型模板类</h3>
<h4 id="源代码实现">源代码实现</h4>
<blockquote>
<p>我先是画出规划图进行实现，然后在实现的过程中，发现可以新增一些特性，比如重载下标运算符，比如用print函数打印出来方便验证。</p>
</blockquote>
<p>具体实现过程，为了方便简单的定位可能发生的错误，使用了大量的assert进行断言检查。如果想代码的健壮性更强，可以使用抛出异常的方式。</p>
<p>源代码对应的GitHub仓库地址：<a href="https://github.com/ACking-you/my_tiny_stl" target="_blank" rel="noopener noreffer">仓库链接，还有更多模板的实现，包括少量STL</a></p>
<p>更好的源码阅读体验：<a href="https://github1s.com/ACking-you/my_tiny_stl/blob/HEAD/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%A8%A1%E6%9D%BF%E7%9A%84%E5%B0%81%E8%A3%85/Matrix.hpp" target="_blank" rel="noopener noreffer">源码在线阅读</a></p>
<blockquote>
<p>直接阅读下面的代码有点不太好查看，推荐去上面的GitHub1s里面查看源码。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//
</span><span class="c1">// Created by L_B__ on 2021/11/20.
</span><span class="c1">//
</span><span class="c1"></span>
<span class="cp">#ifndef LQTEST_MATRIX_H
</span><span class="cp">#define LQTEST_MATRIX_H
</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;cassert&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;algorithm&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp"></span>
<span class="cp">#define _MOD
</span><span class="cp"></span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="k">class</span> <span class="nc">Matrix</span> <span class="p">{</span>
    <span class="cm">/*Type define*/</span>
    <span class="k">typedef</span> <span class="n">T</span> <span class="n">data_t</span><span class="p">;</span>
    <span class="k">typedef</span> <span class="kt">int</span> <span class="n">ssize_t</span><span class="p">;</span>
    <span class="cm">/*data source*/</span>
    <span class="n">data_t</span> <span class="o">**</span><span class="n">data</span><span class="p">;</span>
    <span class="n">ssize_t</span> <span class="n">n</span><span class="p">;</span>
    <span class="n">ssize_t</span> <span class="n">m</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span>
    <span class="k">static</span> <span class="k">const</span> <span class="n">data_t</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span>
    <span class="cm">/*default construct*/</span>
    <span class="n">Matrix</span><span class="p">()</span> <span class="o">:</span> <span class="n">m</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">n</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">data</span><span class="p">(</span><span class="k">nullptr</span><span class="p">)</span> <span class="p">{}</span>

    <span class="cm">/*custom construct*/</span>
    <span class="n">Matrix</span><span class="p">(</span><span class="n">data_t</span> <span class="o">**</span><span class="n">mat</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">n</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">m</span><span class="p">)</span> <span class="o">:</span> <span class="n">data</span><span class="p">(</span><span class="n">mat</span><span class="p">),</span> <span class="n">n</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">m</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="p">{}</span><span class="c1">//外部申请内存传入内部
</span><span class="c1"></span>    <span class="n">Matrix</span><span class="p">(</span><span class="n">ssize_t</span> <span class="n">n</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">m</span><span class="p">)</span> <span class="o">:</span> <span class="n">data</span><span class="p">(</span><span class="k">nullptr</span><span class="p">),</span> <span class="n">n</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">m</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="p">{</span><span class="c1">//外部指定矩阵的行和列即可，内存初始化在内部进行
</span><span class="c1"></span>        <span class="n">assert</span><span class="p">(</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">data</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span><span class="p">[</span><span class="n">m</span><span class="p">];</span>
        <span class="p">}</span>
        <span class="n">init</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="cm">/*copy construct*/</span>
    <span class="n">Matrix</span><span class="p">(</span><span class="n">Matrix</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span> <span class="o">:</span> <span class="n">data</span><span class="p">(</span><span class="k">nullptr</span><span class="p">),</span> <span class="n">n</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="p">),</span> <span class="n">m</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">)</span><span class="c1">//也可用const &amp;引用类型，但这样很多右值的情况都不会调用移动构造了
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">data</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span><span class="p">[</span><span class="n">m</span><span class="p">];</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">m</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="cm">/*move construct*/</span>
    <span class="n">Matrix</span><span class="p">(</span><span class="n">Matrix</span><span class="o">&lt;</span><span class="n">data_t</span><span class="o">&gt;</span> <span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">)</span> <span class="o">:</span> <span class="n">n</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="p">),</span> <span class="n">m</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">),</span> <span class="n">data</span><span class="p">(</span><span class="k">nullptr</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">;</span>
        <span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
        <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="cm">/*destruct*/</span>
    <span class="o">~</span><span class="n">Matrix</span><span class="p">()</span> <span class="p">{</span>
        <span class="n">destroy</span><span class="p">();</span>
    <span class="p">}</span>


    <span class="cm">/*overload*/</span>
    <span class="c1">//加上MOD的特殊版本
</span><span class="c1"></span>    <span class="cp">#ifdef _MOD
</span><span class="cp"></span>
    <span class="n">Matrix</span> <span class="k">operator</span><span class="o">*</span><span class="p">(</span><span class="k">const</span> <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">data_t</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//建议返回右值，返回左值的后续坑比较多，参数const &amp;既可以接受左值也可接受右值
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">==</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span><span class="c1">//进行矩阵乘法的必要条件
</span><span class="c1"></span>        <span class="n">data_t</span> <span class="o">**</span><span class="n">tmp</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span> <span class="c1">//为tmp申请动态内存，因为是传出参数
</span><span class="c1"></span>        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span><span class="p">[</span><span class="n">m</span><span class="p">];</span>
        <span class="p">}</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span><span class="c1">//开始更新tmp
</span><span class="c1"></span>        <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">data_t</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">k</span><span class="p">)</span> <span class="p">{</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//直接构造匿名对象返回
</span><span class="c1"></span>        <span class="k">return</span> <span class="nf">Matrix</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">);;</span>
    <span class="p">}</span>

    <span class="n">Matrix</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">*=</span><span class="p">(</span><span class="k">const</span> <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">data_t</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//*= 想一想我们平时的使用，就是返回一个左值
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">==</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span><span class="c1">//进行矩阵乘法的必要条件
</span><span class="c1"></span>        <span class="n">data_t</span> <span class="n">tmp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">];</span><span class="c1">//静态内存就行，毕竟只是临时存数据的
</span><span class="c1"></span>        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span><span class="c1">//开始更新tmp
</span><span class="c1"></span>        <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">data_t</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">k</span><span class="p">)</span> <span class="p">{</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//由于此时的date内存可能不够容下tmp数据，所以可能需要重新进行内存申请
</span><span class="c1"></span>        <span class="c1">//注意重新申请列内存的时候，需要把之前的内存释放
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o">!=</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">delete</span><span class="p">[]</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
                <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
                <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span><span class="p">[</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">];</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">assert</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">!=</span> <span class="k">nullptr</span><span class="p">);</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="cp">#endif
</span><span class="cp"></span>
    <span class="cp">#ifndef _MOD
</span><span class="cp"></span>    <span class="n">Matrix</span> <span class="k">operator</span><span class="o">*</span><span class="p">(</span><span class="k">const</span> <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">data_t</span><span class="o">&gt;&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//建议返回右值，返回左值的后续坑比较多，参数const &amp;既可以接受左值也可接受右值
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">data</span><span class="o">!=</span> <span class="k">nullptr</span><span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="o">!=</span> <span class="k">nullptr</span><span class="o">&amp;&amp;</span><span class="n">m</span><span class="o">==</span><span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="o">&amp;&amp;</span><span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">n</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span><span class="c1">//进行矩阵乘法的必要条件
</span><span class="c1"></span>        <span class="n">data_t</span><span class="o">**</span> <span class="n">tmp</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span> <span class="c1">//为tmp申请动态内存，因为是传出参数
</span><span class="c1"></span>        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="p">[</span><span class="n">m</span><span class="p">];</span>
        <span class="p">}</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="o">++</span><span class="n">i</span><span class="p">)</span><span class="c1">//开始更新tmp
</span><span class="c1"></span>        <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">data_t</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">k</span><span class="p">)</span> <span class="p">{</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="n">sum</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//直接构造匿名对象返回
</span><span class="c1"></span>        <span class="k">return</span> <span class="nf">Matrix</span> <span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="cm">/*与乘法的唯一区别在于乘法是构造一个新的对象，而*=返回的是this*/</span>
    <span class="n">Matrix</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">*=</span><span class="p">(</span><span class="k">const</span> <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">data_t</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//*= 想一想我们平时的使用，就是返回一个左值
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">data</span><span class="o">!=</span> <span class="k">nullptr</span><span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="o">!=</span> <span class="k">nullptr</span><span class="o">&amp;&amp;</span><span class="n">m</span><span class="o">==</span><span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="o">&amp;&amp;</span><span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">n</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span><span class="c1">//进行矩阵乘法的必要条件
</span><span class="c1"></span>        <span class="n">data_t</span> <span class="n">tmp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">];</span><span class="c1">//静态内存就行，毕竟只是临时存数据的
</span><span class="c1"></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="o">++</span><span class="n">i</span><span class="p">)</span><span class="c1">//开始更新tmp
</span><span class="c1"></span>        <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">data_t</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
                <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">k</span><span class="p">)</span> <span class="p">{</span>
                    <span class="n">sum</span> <span class="o">=</span> <span class="n">sum</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
                <span class="p">}</span>
                <span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//由于此时的date内存可能不够容下tmp数据，所以可能需要重新进行内存申请
</span><span class="c1"></span>        <span class="c1">//注意重新申请列内存的时候，需要把之前的内存释放
</span><span class="c1"></span>        <span class="k">if</span><span class="p">(</span><span class="n">m</span><span class="o">!=</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">){</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">delete</span> <span class="p">[]</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
                <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
                <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="p">[</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">];</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">assert</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">!=</span> <span class="k">nullptr</span><span class="p">);</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">,</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="cp">#endif
</span><span class="cp"></span>

    <span class="c1">//赋值号的重载需要对左右值情况进行分开处理以达到拷贝：该深则深，该浅则浅
</span><span class="c1"></span>    <span class="n">Matrix</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">Matrix</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//如果右边是左值，则需要深拷贝（不拷贝指针
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">destroy</span><span class="p">();</span><span class="c1">//拷贝前进行内存的清除
</span><span class="c1"></span>        <span class="n">n</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="p">;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span> <span class="o">*</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">assert</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">!=</span> <span class="k">nullptr</span><span class="p">);</span><span class="c1">//其实没太大必要，因为new申请失败会抛出bad_alloc异常
</span><span class="c1"></span>            <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="n">data_t</span><span class="p">[</span><span class="n">m</span><span class="p">];</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">m</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">Matrix</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">Matrix</span> <span class="o">&amp;&amp;</span><span class="n">src</span><span class="p">)</span><span class="c1">//如果右边是右值，则进行浅拷贝
</span><span class="c1"></span>    <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">destroy</span><span class="p">();</span><span class="c1">//拷贝前进行内存的清除
</span><span class="c1"></span>        <span class="n">n</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">n</span><span class="p">;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span><span class="p">;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">data</span><span class="p">;</span>

        <span class="n">src</span><span class="p">.</span><span class="n">data</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
        <span class="n">src</span><span class="p">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">m</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">data_t</span> <span class="o">*&amp;</span><span class="k">operator</span><span class="p">[](</span><span class="n">ssize_t</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">i</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">);</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
    <span class="p">}</span>


    <span class="cm">/*快速幂实现，面向对象的接口*/</span>
    <span class="kt">void</span> <span class="nf">quickPow</span><span class="p">(</span><span class="n">data_t</span> <span class="n">c</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">QPow</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">c</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="cm">/*setter和getter实现*/</span>
    <span class="kt">void</span> <span class="nf">set</span><span class="p">(</span><span class="n">ssize_t</span> <span class="n">x</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">y</span><span class="p">,</span> <span class="n">data_t</span> <span class="n">src</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">n</span> <span class="o">&amp;&amp;</span> <span class="n">y</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">);</span>
        <span class="n">data</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o">=</span> <span class="n">src</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">data_t</span> <span class="o">&amp;</span><span class="n">get</span><span class="p">(</span><span class="n">ssize_t</span> <span class="n">x</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">y</span><span class="p">)</span> <span class="p">{</span>
        <span class="c1">//返回一个引用，可以在外界直接修改，当然外界也要用引用来接住，否则还只是一个拷贝
</span><span class="c1"></span>        <span class="n">assert</span><span class="p">(</span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">n</span> <span class="o">&amp;&amp;</span> <span class="n">y</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">);</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">print</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39; &#39;</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>

<span class="k">public</span><span class="o">:</span>
    <span class="k">static</span> <span class="kt">void</span> <span class="n">init</span><span class="p">(</span><span class="n">data_t</span> <span class="o">**</span><span class="n">data</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">n</span><span class="p">,</span> <span class="n">ssize_t</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">data</span> <span class="o">!=</span> <span class="k">nullptr</span> <span class="o">&amp;&amp;</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">m</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">);</span>

        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">j</span><span class="p">)</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
                <span class="k">else</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="k">static</span> <span class="kt">void</span> <span class="nf">QPow</span><span class="p">(</span><span class="n">Matrix</span> <span class="o">&amp;</span><span class="n">_Dest</span><span class="p">,</span> <span class="n">data_t</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">assert</span><span class="p">(</span><span class="n">n</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">);</span>
        <span class="n">Matrix</span> <span class="n">tmp</span><span class="p">(</span><span class="n">_Dest</span><span class="p">);</span><span class="c1">//制造一份拷贝，用于倍增
</span><span class="c1"></span>        <span class="n">init</span><span class="p">(</span><span class="n">_Dest</span><span class="p">.</span><span class="n">data</span><span class="p">,</span> <span class="n">_Dest</span><span class="p">.</span><span class="n">n</span><span class="p">,</span> <span class="n">_Dest</span><span class="p">.</span><span class="n">m</span><span class="p">);</span><span class="c1">//初始化为单位矩阵
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
            <span class="k">return</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">&amp;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">_Dest</span> <span class="o">*=</span> <span class="n">tmp</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">tmp</span> <span class="o">*=</span> <span class="n">tmp</span><span class="p">;</span>
            <span class="n">n</span> <span class="o">&gt;&gt;=</span> <span class="mi">1</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>

<span class="k">private</span><span class="o">:</span>
    <span class="kt">void</span> <span class="n">destroy</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">data</span> <span class="o">==</span> <span class="k">nullptr</span><span class="p">)</span>
            <span class="k">return</span><span class="p">;</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="k">nullptr</span><span class="p">)</span><span class="c1">//如果这片内存中有nullptr，则说明之前已经被delete过了
</span><span class="c1"></span>                <span class="k">return</span><span class="p">;</span>
            <span class="k">delete</span><span class="p">[]</span> <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
            <span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">delete</span><span class="p">[]</span> <span class="n">data</span><span class="p">;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>


<span class="cp">#endif </span><span class="c1">//LQTEST_MATRIX_H
</span><span class="c1"></span>
</code></pre></div><h4 id="使用方法">使用方法</h4>
<ul>
<li>使用说明：通过宏定义的方式在内部实现了两套乘法代码，一套是不对MOD取模的，一套则是取模，但必须先在外部对MOD赋初值。</li>
</ul>
<p>最终的使用示例：</p>
<blockquote>
<p>我们来使用只需要关心两点：1.矩阵类的构造和初始化 2.基本成员函数的使用</p>
</blockquote>
<h4 id="一-矩阵类的构造和初始化方式">一、 矩阵类的构造和初始化方式</h4>
<blockquote>
<p>由于是模板类，所以需要明确模板的类型</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span> <span class="cpf">&#34;Matrix.h&#34;</span><span class="cp">
</span><span class="cp"></span><span class="c1">//下面的dataType为你所需要的矩阵每个元素的数据类型，需要你自己传入
</span><span class="c1"></span><span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">dataType</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">;</span><span class="c1">//缺省构造
</span><span class="c1"></span>
    <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">dataType</span><span class="o">&gt;</span> <span class="n">b</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">);</span><span class="c1">//得到三行三列的矩阵，默认为单位矩阵
</span><span class="c1"></span>
    <span class="kt">int</span><span class="o">**</span> <span class="n">ret</span> <span class="o">=</span> <span class="k">new</span> <span class="p">...</span><span class="c1">//此处省略总之就是申请了二维的内存
</span><span class="c1"></span>    <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">dataType</span><span class="o">&gt;</span> <span class="n">c</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">);</span><span class="c1">//外界申请内存并赋初值然后对类进行初始化
</span><span class="c1"></span>
    <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">dataType</span><span class="o">&gt;</span> <span class="n">d</span><span class="p">(</span><span class="n">c</span><span class="p">);</span><span class="n">or</span> <span class="n">Matrix</span> <span class="n">d</span> <span class="o">=</span> <span class="n">c</span><span class="p">;</span><span class="c1">//利用已经存在的类初始化d对象(会创建新的内存)
</span><span class="c1"></span>
    <span class="n">Matrix</span><span class="o">&lt;</span><span class="n">dataType</span><span class="o">&gt;</span> <span class="n">e</span><span class="p">(</span><span class="n">c</span><span class="o">*</span><span class="n">d</span><span class="p">);</span><span class="n">or</span> <span class="n">Matrix</span> <span class="n">e</span> <span class="o">=</span> <span class="n">c</span><span class="o">*</span><span class="n">d</span><span class="p">;</span><span class="c1">//通过临时对象初始化(不会创建新的内存)
</span><span class="c1"></span><span class="p">}</span>
</code></pre></div><blockquote>
<p>对应源码：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/6c891afa02b44923b6cbe5992cceab36.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
</blockquote>
<h4 id="二基本成员函数的使用">二、基本成员函数的使用</h4>
<blockquote>
<p>主要是使用快速幂的函数。当然由于已经重载了乘法，所以只要两个矩阵能够相乘，则可以直接进行乘法得出结果。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span> <span class="cpf">&#34;Matrix.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="c1">//初始化a矩阵为{{1,1},{1,0}}
</span><span class="c1"></span>   <span class="n">Matrix</span><span class="o">&lt;</span><span class="kt">long</span> <span class="kt">long</span> <span class="o">&gt;</span> <span class="n">a</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>

    <span class="kt">int</span> <span class="n">c</span><span class="p">;</span> <span class="n">cin</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">;</span>
    <span class="c1">//调用快速幂将矩阵的数据更新为c次方
</span><span class="c1"></span>    <span class="n">a</span><span class="p">.</span><span class="n">quickPow</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>

    <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span><span class="n">or</span> <span class="n">a</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span><span class="c1">//可以访问a的(0,0)位置的元素
</span><span class="c1"></span>
    <span class="n">a</span><span class="p">.</span><span class="n">print</span><span class="p">()</span>       <span class="c1">//打印出矩阵的当前值
</span><span class="c1"></span>                    <span class="c1">//比如a现在为{{1,1}{1,0}}
</span><span class="c1"></span>                    <span class="c1">// 则打印：
</span><span class="c1"></span>                    <span class="c1">//1 1
</span><span class="c1"></span>                    <span class="c1">//1 0
</span><span class="c1"></span><span class="p">}</span>
</code></pre></div><blockquote>
<p>如果想得到模MOD的快速幂结果，则需要在Matrix文件前面加一个宏定义 <code>_MOD</code> 再按照以下方式使用：</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span> <span class="cpf">&#34;Matrix.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="k">template</span><span class="o">&lt;&gt;</span> <span class="k">const</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">Matrix</span><span class="o">&lt;</span><span class="kt">long</span> <span class="kt">long</span><span class="o">&gt;::</span><span class="n">MOD</span> <span class="o">=</span> <span class="mf">1e9</span><span class="o">+</span><span class="mi">7</span><span class="p">;</span><span class="c1">//初始化MOD的值
</span><span class="c1"></span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="n">Matrix</span><span class="o">&lt;</span><span class="kt">long</span> <span class="kt">long</span> <span class="o">&gt;</span> <span class="n">a</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>

    <span class="n">Matrix</span><span class="o">&lt;</span><span class="kt">long</span> <span class="kt">long</span><span class="o">&gt;</span> <span class="n">b</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
    <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>

    <span class="kt">long</span> <span class="kt">long</span> <span class="n">c</span><span class="p">;</span>

    <span class="n">std</span><span class="o">::</span><span class="n">cin</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">;</span>
    <span class="n">a</span><span class="p">.</span><span class="n">quickPow</span><span class="p">(</span><span class="n">c</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
    <span class="n">b</span> <span class="o">=</span> <span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">;</span>
    <span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
</code></pre></div><blockquote>
<p>对应源码：
MOD版本：<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/6c3590efb3674927be4c92fce378903c.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/b4d82512168344c8b8dc100ad855bc58.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
</blockquote>
<blockquote>
<p>非MOD版本：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/69ed2e5f43a04291a1f4a280582ec264.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/7b7fbd2c14b240a1a29882fa1d4cfd64.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
</blockquote>
<blockquote>
<p>k快速幂实现：<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/35b33f1fe05449fb8dd9e275ee8ba0c7.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/eaa452fd32f647cd891f6d8c0bf3ff7a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16" /></p>
</blockquote>
<h4 id="三解题验证">三、解题验证</h4>
<ul>
<li>由于lanqiao网不支持C++11，所以我直接本地输入测试用例进行测试。</li>
</ul>
<p>先测一简单的：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/6d8de75b3fad459ab13239537e1599f9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<p>往大了测测：
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/57bfad88b35f4f628a8c1bdd27483c30.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" />
再大一点（应该是long long的极限了）<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/c8a3db4809db40eda5eba005e595d99f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<blockquote>
<p>依旧稳定1ms左右！！！！我只能说两个字：优秀！</p>
</blockquote>
<h2 id="总结">总结</h2>
<p>由于用的是 C++11 的语法进行实现的模板类，所以低于这个版本的编译器都无法正常使用。我查阅了相关资料，实际上蓝桥杯比赛的时候可以用 C++11，而acm更是不用说，早就能用C++11了。</p>
<p><strong>简单复盘：</strong>
实现一个这样的类，主要能学到以下几点：</p>
<ol>
<li>类的设计技巧。</li>
<li>对C++的左右值有了更深入的理解。</li>
<li>各种构造器的设计和实现已经达到炉火纯青的地步了。</li>
</ol>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82/">矩阵快速幂</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-01-20</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装" data-hashtags="矩阵快速幂"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-hashtag="矩阵快速幂"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装" data-image="https://img-blog.csdnimg.cn/img_convert/687db1a327b1ff978e25faf116abe71a.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装" data-description="矩阵快速幂的C&#43;&#43;封装"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装" data-description="矩阵快速幂的C&#43;&#43;封装"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" data-title="矩阵快速幂的C&#43;&#43;封装"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/%E6%89%8B%E5%86%99http%E5%8D%8F%E8%AE%AE%E8%A7%A3%E6%9E%90%E5%99%A8/" class="prev" rel="prev" title=""><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" class="next" rel="next" title="大数加减类的实现(C&#43;&#43;实现)✨">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
